/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Pantalla.java
 *
 * Created on 12-02-2012, 07:01:14 PM
 */
package Estructura;

import java.awt.BorderLayout;
import java.net.URL;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


/**
 *
 * @author Roberto A Pinto S
 */
public class Pantalla extends javax.swing.JFrame {
         private static Logger logger = Logger.getLogger(Pantalla.class);

    private PanelDibujo miPanel;
    private Ordenamientos miModelo;

    /** Creates new form Pantalla */
    public Pantalla() {
        this.miPanel = new PanelDibujo();
        this.miModelo = new Ordenamientos(300);
        this.getContentPane().add(this.miPanel);
        this.miModelo.addObserver(this.miPanel);
        
        initComponents();
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(this.miPanel, BorderLayout.CENTER);
        
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jMenu1.setText("File");

        jMenuItem1.setText("Insercion");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Quicksort");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Seleccion");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setText("Desordenar");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setText("Salir");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 277, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    //Ordenamientos obj=new Ordenamientos(200);
    /**Ordenamientos obj=new Ordenamientos(300);
    Thread worker = new Thread(new Runnable){
        public void run(){
        Ordenamientos obj= new Ordenamientos(this.obj.Insercion(getArreglo()));
        }
        
    }*/
    //this.miPanel=new PanelDibujo();
    //obj.quiksort(obj.getArreglo(), 1, 99);
    this.miPanel.setObj(this.miModelo);
    this.miPanel.Insercion();
    this.miPanel.pintadoinsercion(this.getGraphics());
    this.miPanel.repaint();
    //logger.debug("Seleccion");

    //miPanel.pintado(null);
    
    
    
}//GEN-LAST:event_jMenuItem1ActionPerformed
    
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
    //Ordenamientos obj = new Ordenamientos(200);
  // System.out.println("hola");
   // this.miPanel.removeAll();    
   // this.miModelo.quiksort(this.miModelo.getArreglo(), 1, 99);
    //this.miPanel.setObj(this.miModelo);
    //this.miPanel.QuickSort();
    this.miPanel.pintadoquicksort(this.getGraphics());
    this.miPanel.repaint();
    this.miPanel.validate();
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
// TODO add your handling code here:
    this.miPanel.removeAll();    
   // this.miModelo.quiksort(this.miModelo.getArreglo(), 1, 99);
    //this.miPanel.setObj(this.miModelo);
    this.miModelo.desordenar();
    //this.miPanel.pintado(this.getGraphics());
    this.miPanel.repaint();
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
// TODO add your handling code here:
    logger.info("Termina la ejecucion del programa");
    System.exit(0);
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
// TODO add your handling code here:
    logger.info("Pinta al metodo Seleccion");
    this.miPanel.removeAll();    
   // this.miModelo.quiksort(this.miModelo.getArreglo(), 1, 99);
    this.miPanel.setObj(this.miModelo);
    //this.miPanel.QuickSort();
    this.miPanel.pintadoseleccion(this.getGraphics());
    
    this.miPanel.repaint();
    this.miPanel.validate();
}//GEN-LAST:event_jMenuItem3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        String resource = "/Auditoria.properties";
        URL configFileResource;
    configFileResource = Pantalla.class.getResource(resource);
    configFileResource = PanelDibujo.class.getResource(resource);
    configFileResource = Ordenamientos.class.getResource(resource);
    PropertyConfigurator.configure(configFileResource);
    logger.info("Se inicializa el arreglo");
    //Ordenamientos log = new Ordenamientos(300);
    //log.desordenar();
    
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Pantalla.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Pantalla.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Pantalla.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Pantalla.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            
            public void run() {
                
                new Pantalla().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    // End of variables declaration//GEN-END:variables
}
